package com.util;

import java.util.List;

import com.github.pagehelper.Page;

public class BeanUtil {

    public static <T> PagedResult<T> toPagedResult(List<T> datas) {
        PagedResult<T> result = new PagedResult<T>();
        if (datas instanceof Page) {
            Page page = (Page) datas;
            result.setPage(page.getPageNum());           //当前页
            result.setRows(page.getPageSize());          //行数
            result.setDataList(page.getResult());          
            result.setTotal(page.getPages());           //总页面数目
            result.setRecord((int) page.getTotal());    //查询出的记录数
        }
        else {
            result.setPage(1);
            result.setRows(datas.size());
            result.setDataList(datas);
            result.setTotal(datas.size());
        }
        return result;
    }

}
